package com.ls.thread.xww;

public class Signal1 implements Runnable{
	private int carNumber=100;
	private boolean flag=true;
	@Override
	public synchronized void run() {
		while(flag){
			try {
				if(carNumber>0){
					int counter=4;
					System.out.println("绿灯车辆可以通行");
					while(counter>0){
					notify();
					System.out.println(Thread.currentThread().getName()+"第"+carNumber--+"辆车通过");
					Thread.sleep(1000);
					counter--;
					}
					System.out.println("红灯倒计时2");
					Thread.sleep(1000);
					System.out.println("红灯倒计时1");
					Thread.sleep(1000);
					wait();
				}else{
					notifyAll();
					System.out.println("车辆已经全部通过。。。。。"+Thread.currentThread().getName()+"退出循环。。。。。");
					break;
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			/*flag=false;*/
		}
	}
}
